<template>
  <el-container>
    <el-main>
      <el-form ref="form" label-width="80px">
        <el-form-item size="medium" label="商品名称">
          <el-input v-model="form.name"></el-input>
        </el-form-item>

        <el-form-item label="商品分类">
          <el-select
            v-model="form.name"
            clearable
            placeholder="请选择"
            @change="xia"
          >
            <el-option
              v-for="item in brr"
              :key="item.id"
              :label="item.html + item.cate_name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="商品关键">
          <el-input v-model="form.name"></el-input>
        </el-form-item>

        <el-form-item label="单位">
          <el-input v-model="form.name"></el-input>
        </el-form-item>

        <el-form-item label="简介">
          <el-input type="textarea" v-model="form.desc"></el-input>
        </el-form-item>

        <el-form-item label="商品封面">
          <el-upload
            class="avatar-uploader"
            action="https://jsonplaceholder.typicode.com/posts/"
            :show-file-list="false"
            :on-success="handleAvatarSuccess"
            :before-upload="beforeAvatarUpload"
          >
            <img v-if="form.image" :src="form.image" class="avatar" />
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </el-form-item>

        <el-form-item label="商品轮播">
          <el-upload
            class="avatar-uploader"
            action="https://jsonplaceholder.typicode.com/posts/"
            :show-file-list="false"
            :on-success="handleAvatarSuccess"
            :before-upload="beforeAvatarUpload"
          >
            <img v-if="form.image" :src="form.image" class="avatar" />
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </el-form-item>

        <el-form-item label="主图视频">
          <el-button type="primary">上传视频</el-button>
        </el-form-item>

        <el-form-item label="商品规格">
          <el-radio-group v-model="form.resource">
            <el-radio label="单规格"></el-radio>
            <el-radio label="多规格"></el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
    </el-main>
  </el-container>
</template>

<script>
import { fen } from "../api/index";
export default {
  data() {
    return {
      form: {
        name: "",
        value: "",
        image: "",
        resource:"单规格"
      },
      brr: [],
    };
  },
  created() {
    fen().then((res) => {
      console.log(res.data.data);
      this.brr = res.data.data;
    });
  },

  methods: {
    handleAvatarSuccess(res, file) {
      this.imageUrl = URL.createObjectURL(file.raw);
    },
    beforeAvatarUpload(file) {
      const isJPG = file.type === "image/jpeg";
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isJPG) {
        this.$message.error("上传头像图片只能是 JPG 格式!");
      }
      if (!isLt2M) {
        this.$message.error("上传头像图片大小不能超过 2MB!");
      }
      return isJPG && isLt2M;
    },
    xia() {},
  },
};
</script>
<style lang='scss' scoped>
.el-header,
.el-footer {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 60px;
}
.el-container {
  width: 100%;
  height: 100%;
}
.el-main {
  background-color: #e9eef3;
  color: #333;
  width: 100%;
  height: 100%;
}
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 58px;
  height: 58px;
  line-height: 58px;
  text-align: center;
}
.avatar {
  width: 58px;
  height: 58px;
  display: block;
}
</style>